//
//  ECMineCourseSubCell.m
//  Edu_iOS2018
//
//  Created by apple on 2018/1/17.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#import "ECMineCourseSubCell.h"
#import "ECMineCourseSubModel.h"

@interface ECMineCourseSubCell(){
    ///头像image
    UIImageView *iconImage;
    ///星星image
    UIImageView *starImage;
    ///课程名lab
    UILabel *titleLab;
    ///时间lab
    UILabel *timeLab;
    ///内容lab
    UILabel *contentLab;
}

@end

@implementation ECMineCourseSubCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        [self setCellUI];
    }
    return self;
}

-(void)setCellUI{
    
    iconImage = [[UIImageView alloc]init];
    [self.contentView addSubview:iconImage];
    iconImage.layer.masksToBounds = YES;
    iconImage.layer.cornerRadius = 3.f;
    
    titleLab = [[UILabel alloc]init];
    [self.contentView addSubview:titleLab];
    titleLab.font = [UIFont systemFontOfSize:14*kPercentage];
    titleLab.textColor = [UIColor colorWithHexString:@"#454545"];
    
    starImage = [[UIImageView alloc]init];
    [self.contentView addSubview:starImage];
    
    timeLab = [[UILabel alloc]init];
    [self.contentView addSubview:timeLab];
    timeLab.font = [UIFont systemFontOfSize:12*kPercentage];
    timeLab.textColor = [UIColor colorWithHexString:@"#BFBFBF"];
    
    contentLab = [[UILabel alloc]init];
    [self.contentView addSubview:contentLab];
    contentLab.numberOfLines = 0;
    contentLab.font = [UIFont systemFontOfSize:13*kPercentage];
    contentLab.textColor = [UIColor colorWithHexString:@"#6D7689"];
    
    UIView *lineView = [[UILabel alloc]init];
    [self.contentView addSubview:lineView];
    lineView.backgroundColor = [UIColor colorWithHexString:@"#E5E5E5"];
    
    WeakSelf(weakSelf);
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_left).offset(kProportion_Width(45));
        make.top.equalTo(weakSelf.contentView.mas_top).offset(kProportion_Height(60));
        make.width.height.equalTo(@(kProportion_Height(110)));
    }];
    
    [starImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.contentView.mas_right).offset(-kProportion_Width(45));
        make.centerY.equalTo(titleLab.mas_centerY);
        make.width.equalTo(@(kProportion_Width(200)));
        make.height.equalTo(starImage.mas_width).multipliedBy(24.f/131.f);
    }];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImage.mas_right).offset(kProportion_Width(35));
        make.right.equalTo(starImage.mas_left).offset(kProportion_Width(-45));
        make.top.equalTo(iconImage.mas_top);
        make.height.equalTo(@16);
    }];
    
    [timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_left);
        make.bottom.equalTo(iconImage.mas_bottom);
        make.width.equalTo(titleLab.mas_width);
        make.height.equalTo(@15);
    }];
    
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(timeLab.mas_bottom).offset(kProportion_Height(35));
        make.left.equalTo(titleLab.mas_left);
        make.right.equalTo(starImage.mas_right);
        make.bottom.equalTo(lineView.mas_top).offset(-kProportion_Height(35));
    }];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_left);
        make.right.equalTo(starImage.mas_right);
        make.bottom.equalTo(weakSelf.contentView.mas_bottom);
        make.height.equalTo(@1);
    }];
    
}

-(void)setContentMode:(ECMineCourseSubModel *)contentMode{
    [iconImage sd_setImageWithURL:[NSURL URLWithString:contentMode.course.middlePicture] placeholderImage:[UIImage imageNamed:kEduCourseImagePlaceholderName]];
    titleLab.text = contentMode.course.title;
    timeLab.text = contentMode.createdTime;
    
    //判断用户评价
    if ([contentMode.content isEqualToString:@""] || contentMode.content == NULL || contentMode.content == nil) {
        contentLab.text = @"此用户没有填写评价";
    }else{
        contentLab.text = contentMode.content;
    }
    
    //根据不同数字 加载不同评价级别图片
    switch ([contentMode.rating intValue]) {
        case 1:
            starImage.image = [UIImage imageNamed:@"Mine_star_one"];
            break;
        case 2:
            starImage.image = [UIImage imageNamed:@"Mine_star_two"];
            break;
        case 3:
            starImage.image = [UIImage imageNamed:@"Mine_star_three"];
            break;
        case 4:
            starImage.image = [UIImage imageNamed:@"Mine_star_four"];
            break;
        case 5:
            starImage.image = [UIImage imageNamed:@"Mine_star_five"];
            break;
        default:
            starImage.image = [UIImage imageNamed:@"Mine_star_zero"];

            break;
    }
    
}

@end
